﻿using Autofac;
using System.Reflection;

namespace Fortunate.API.AppCode
{
    /// <summary>
    /// 依赖自动注入
    /// </summary>
    public class DependencyAutoInjection : Autofac.Module
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="builder"></param>
        protected override void Load(ContainerBuilder builder)
        {
            //业务逻辑层程序集
            Assembly service = Assembly.Load("Fortunate.Service");
            //数据库访问层程序集
            Assembly repository = Assembly.Load("Fortunate.IService");

            //自动注入
            builder.RegisterAssemblyTypes(service).Where(t => t.Name.EndsWith("Service")).AsImplementedInterfaces();
            //自动注入
            builder.RegisterAssemblyTypes(repository).Where(t => t.Name.EndsWith("IService")).AsImplementedInterfaces();
        }
    }
}
